/*
 *
 * Created on 15-dic-2011, 17.28.15
 */

package sybel.pan;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import sybel.DOMPanelInterface;

/**
 * @author Stefano
 */
public class Entity extends javax.swing.JPanel implements DOMPanelInterface{

    /** Creates new form Entity */
    public Entity(Node Father) {
        Parent = Father;
        NodeList nl = ((Element)Father).getElementsByTagName("entity");
        Entity = (Element)nl.item(0);
        initComponents();
        if(Entity != null)
            initPanel();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTextField1 = new javax.swing.JTextField();

        setBorder(javax.swing.BorderFactory.createTitledBorder("Entity"));

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 146, Short.MAX_VALUE)
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 20, Short.MAX_VALUE)
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    public void initPanel(){
        jTextField1.setText(Entity.getTextContent());
    }


    public Node saveData(){
        Document doc = Parent.getOwnerDocument();
        Entity = doc.createElement("entity");
        Entity.setTextContent(jTextField1.getText());

        return (Node)Entity;
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
    private Element Entity;
    private Node Parent;
}
